package com.future.direction.ui.activity;

import android.content.Intent;
import android.os.Bundle;
import android.text.Editable;
import android.text.TextWatcher;
import android.view.View;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.TextView;

import com.future.direction.R;
import com.future.direction.di.component.AppComponent;
import com.future.direction.ui.widget.MyTitleBar;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * Created by XWL on 2020/2/11.
 * Description: 推荐码填写
 */
public class ReferralCodeActivity extends BaseActivity implements View.OnClickListener {


    @BindView(R.id.titleBar)
    MyTitleBar titleBar;
    @BindView(R.id.et_referral_code)
    EditText etReferralCode;
    @BindView(R.id.tv_accomplish)
    TextView tvAccomplish;
    @BindView(R.id.iv_edit_clear)
    ImageView ivEditClear;
    @BindView(R.id.view_referral_code)
    View viewReferralCode;

    @Override
    public int setLayout() {
        return R.layout.activity_referral_code;
    }

    @Override
    public void getExtras() {

    }

    @Override
    public boolean init() {
        return false;
    }

    @Override
    public void setListener() {
        backListener(titleBar);
        etReferralCode.setOnFocusChangeListener(new View.OnFocusChangeListener() {
            @Override
            public void onFocusChange(View v, boolean hasFocus) {
                if (hasFocus) {
                    viewReferralCode.setBackgroundColor(getResources().getColor(R.color.colorBlue0D7EF9));
                }else {
                    viewReferralCode.setBackgroundColor(getResources().getColor(R.color.colorBlackDCE2E8));
                }
            }
        });
        //推荐码输入监听
        etReferralCode.addTextChangedListener(new TextWatcher() {
            @Override
            public void beforeTextChanged(CharSequence s, int start, int count, int after) {

            }

            @Override
            public void onTextChanged(CharSequence s, int start, int before, int count) {
                if (s.toString().length() >= 1) {
                    ivEditClear.setVisibility(View.VISIBLE);
                } else {
                    ivEditClear.setVisibility(View.GONE);
                }
            }

            @Override
            public void afterTextChanged(Editable s) {

            }
        });
        ivEditClear.setOnClickListener(this);
        tvAccomplish.setOnClickListener(this);
        titleBar.setRightLayoutClickListener(this);

    }

    @Override
    public void setupAcitivtyComponent(AppComponent appComponent) {

    }


    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            //清空输入的推荐码
            case R.id.iv_edit_clear:
                etReferralCode.setText("");
                break;
            case R.id.tv_accomplish:
                goMain();
                break;
            case R.id.right_layout:
                goMain();
                break;
        }
    }

    private void goMain() {
        Intent intent = new Intent(this, MainActivity.class);
        startActivity(intent);
        finish();
    }

}
